﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;
using DomainModel;
using BIZ;

namespace joyAdmin.Controllers
{
    [DomainConfirmationFilter]
    public class memberController : Controller
    {


        #region 登陆页
        public ActionResult Login()
        {
            ViewData["sc"] = Request.Params["from"];
            return View("login");
        }
        #endregion

        #region 退出
        public ActionResult Logout()
        {
            Session["cmsuser"] = null;
            return Login();
        }
        #endregion

        #region 登陆验证
        public ActionResult LoginResult()
        {
            string from = Request.Params["from"];
            if (string.IsNullOrEmpty(from))
                from = "../cms/index.html";
            ViewData["sc"] = from;
            string workid = Request.Form["workid"];
            string pwd = Request.Form["pwd"];
            
            IList list =cmsOper.login(workid,BIZ.StringTool.md5(pwd, 16));
            if (list.Count == 0)
            {
                ViewData["mess"] = "error";
                return View("login");
            }
            else
            {
                Hashtable hs = (Hashtable)list[0];
                Operator oper = new Operator
                {
                    O_id = int.Parse(hs["O_id"].ToString()),
                    O_Workid = hs["O_Workid"].ToString(),
                    O_Password = hs["O_Password"].ToString(),
                    O_Remark = hs["O_Remark"].ToString(),
                    O_Rid = int.Parse(hs["O_Rid"].ToString()),
                    O_Createtime = DateTime.Parse(hs["O_Createtime"].ToString())
                };
                cmsuser user = BIZ.cmsOper.GetCmsUser(oper);
                Session["cmsuser"] = user;
               
                return Redirect(from);
            }
        }
        #endregion

    }
}
